﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.Animations;
using ElfTyping.General;
using Microsoft.Xna.Framework;
using System.Diagnostics;

namespace ElfTyping.States.StoryState
{
    public class StoryState : State
    {
        static Rectangle BackgroundRect = new Rectangle(0, 0, 800, 600);

        Dictionary<Point, Scene> SceneMap;

        public Animation Background { get; set; }

        public string Text { get; set; }

        public FireEmblemPortraitAnimation LeftCharacter { get; set; }
        public Animation LeftCharacterPortrait { get; set; }
        public string LeftCharacterName { get; set; }
        public Point LeftCharacterBottomLeft { get; set; }

        public FireEmblemPortraitAnimation RightCharacter { get; set; }
        public Animation RightCharacterPortrait { get; set; }
        public string RightCharacterName { get; set; }
        public Point RightCharacterBottomLeft { get; set; }
        
        public bool IsLeftCharacterSpeaking { get; set; }
        public bool AreBigPortraitsVisible { get; set; }

        public State NextState { get; set; }

        List<StoryAction> RemainingActions { get; set; }
        TextBox TextBox { get; set; }

        public StoryState(int quest, int chapter)
            : base()
        {
            RemainingActions = new List<StoryAction>();
            TextBox = new TextBox();
            Background = new Animation(@"Textures\Black");
            AreBigPortraitsVisible = true;

            InitializeScene(quest, chapter);
        }

        protected void AddBackground(Animation background)
        {
            RemainingActions.Add(new SetBackgroundAction(this, background)); 
        }

        protected void AddCharacter(string name, bool isLeft)
        {
            RemainingActions.Add(new SetCharacterAction(this, name, isLeft));
        }

        protected void AddText(string text, bool isLeft)
        {
            RemainingActions.Add(new TextAction(this, text, isLeft));
        }

        protected void AddWaitForSpace()
        {
            RemainingActions.Add(new WaitForSpaceAction(this));
        }

        protected void AddChangeState(State nextState)
        {
            RemainingActions.Add(new ChangeStateAction(this, nextState));
        }

        protected void AddSetPortraitVisibility(bool arePortraitsVisible)
        {
            RemainingActions.Add(new SetShowingPortraitsAction(this, arePortraitsVisible));
        }

        protected void AddSetHappiness(bool isHappy, bool isLeft)
        {
            RemainingActions.Add(new SetHappinessAction(this, isHappy, isLeft));
        }

        protected void AddEndQuest()
        {
            RemainingActions.Add(new EndQuestAction(this));
        }

        public override void InitializeState()
        {           
        }

        public override void Draw(General.Camera camera)
        {
            Background.Draw(camera, BackgroundRect);

            if (LeftCharacter != null || RightCharacter != null)
            {

                if (IsLeftCharacterSpeaking)
                {
                    if (LeftCharacter != null)
                    {
                        LeftCharacter.IsActive = true;
                        LeftCharacter.IsSpeaking = true;
                    }

                    if (RightCharacter != null)
                    {
                        RightCharacter.IsActive = false;
                        RightCharacter.IsSpeaking = false;
                    }

                    TextBox.Portrait = LeftCharacterPortrait;
                    TextBox.IsPortraitOnLeft = true;
                    TextBox.Name = LeftCharacterName;
                }
                else
                {
                    if (RightCharacter != null)
                    {
                        RightCharacter.IsActive = true;
                        RightCharacter.IsSpeaking = true;
                    }

                    if (LeftCharacter != null)
                    {
                        LeftCharacter.IsActive = false;
                        LeftCharacter.IsSpeaking = false;
                    }

                    TextBox.Portrait = RightCharacterPortrait;
                    TextBox.IsPortraitOnLeft = false;
                    TextBox.Name = RightCharacterName;
                }

                if (LeftCharacter != null && AreBigPortraitsVisible)
                {
                    LeftCharacter.FlippedHorizontally = true;
                    LeftCharacter.DrawWithBottomLeft(camera, LeftCharacterBottomLeft);
                }

                if (RightCharacter != null && AreBigPortraitsVisible)
                {
                    RightCharacter.FlippedHorizontally = false;
                    RightCharacter.DrawWithBottomLeft(camera, RightCharacterBottomLeft);
                }
            }

            TextBox.IsPortraitOnLeft = IsLeftCharacterSpeaking;
            TextBox.Text = Text;
            TextBox.Draw(camera);
        }

        public override void Tick(float dt)
        {
            Debug.Assert(RemainingActions.Count > 0 || NextState != null);

            if (NextState != null)
            {
                ChangeStateAfterTick(NextState, true);
            }
            else
            {
                while (RemainingActions.Count > 0)
                {
                    RemainingActions[0].Tick(dt);
                    if (RemainingActions[0].IsDone())
                    {
                        RemainingActions[0].OnEnd();
                        RemainingActions.RemoveAt(0);
                    }
                    else
                    {
                        break;
                    }
                }

                TextBox.Tick(dt);
                if (LeftCharacter != null)
                {
                    LeftCharacter.Advance(dt);
                }
                if (RightCharacter != null)
                {
                    RightCharacter.Advance(dt);
                }
            }

            base.Tick(dt);
        }

        public override void HandleInput(General.InputInfo inputInfo)
        {
            if (inputInfo.IsKeyJustPressed(GameKey.Use) && RemainingActions.Count > 0)
            {
                RemainingActions[0].UseKeyPressed();
            }
        }

        public void EndQuest()
        {
            PlayerStatus status = PlayerStatus.GetStatus();
            status.CurrentQuest = 0;
            status.CurrentChapter = 0;
            status.FurthestChapter = status.FurthestChapter + 1;
            status.SaveToXml();

            ChangeStateAfterTick(new CampState.CampState(), true);
        }

        delegate void Scene();
        void InitializeSceneMap()
        {
            if (SceneMap == null)
            {
                SceneMap = new Dictionary<Point, Scene>()
                {
                    {new Point(0,1), new Scene(Scene0_1_FirstLoadIntro)},
                    {new Point(0,2), new Scene(Scene0_2_FirstLoadWakeUp)},
                    {new Point(0,3), new Scene(Scene0_3_FirstLoadRhys)},
                    {new Point(0,4), new Scene(Scene0_4_FirstLoadForest)},
                    {new Point(0,5), new Scene(Scene0_5_FirstLoadElves)},
                    {new Point(1,1), new Scene(Scene1_1)},
                    {new Point(1,2), new Scene(Scene1_2)},
                    {new Point(1,3), new Scene(Scene1_3)},
                    {new Point(1,4), new Scene(Scene1_4)},
                    {new Point(1,5), new Scene(Scene1_5)},
                    {new Point(1,6), new Scene(Scene1_6)},
                    {new Point(1,7), new Scene(Scene1_7)},
                    {new Point(1,8), new Scene(Scene1_8)},
                    {new Point(1,9), new Scene(Scene1_9)},
                };
            }
        }

        void InitializeScene(int quest, int chapter)
        {
            InitializeSceneMap();

            Scene scene = SceneMap[new Point(quest, chapter)];
            scene();
        }

        void Scene0_1_FirstLoadIntro()
        {
            AddSetPortraitVisibility(false);
            AddBackground(new Animation(@"Textures\Black"));
            AddText("...", false);
            AddWaitForSpace();            
            AddText("Ooooh yeah...", false);
            AddWaitForSpace();
            AddText("Oh yeah, lick my nipples harder!", false);
            AddWaitForSpace();
            AddText("Mmmm, I love riding slowly up and down your cock!", false);
            AddWaitForSpace();
            AddText("Let me lean back on your legs so you can grab my wings.", false);
            AddWaitForSpace();
            AddCharacter("Reyson", true);
            AddBackground(new Animation(@"Textures\CG\TibarnReyson-1"));
            AddText(null, true);
            AddWaitForSpace();
            AddText("Oh yeah, oh Tibarn! Grab me tighter!", true);
            AddWaitForSpace();
            AddText("Yeah, stroke it harder...", true);
            AddWaitForSpace();
            AddText("That's it, oh Tibarn! I'm cumming!", true);
            
            AddWaitForSpace();
            AddChangeState(new StoryState(0,2));
        }

        void Scene0_2_FirstLoadWakeUp()
        {
            Background = new Animation(@"Textures\CG\Bedroom");
            AddBackground(Background);
            AddText("Ughhhh... my head...", false);
            AddWaitForSpace();
            AddText("I really put away a lot of mead last night...", false);
            AddWaitForSpace();
            AddCharacter("Shinon", true);
            AddSetHappiness(false, true);
            AddText("...", true);
            AddWaitForSpace();
            AddText("... ...", true);
            AddWaitForSpace();
            AddText("... ... ...", true);
            AddWaitForSpace();
            AddSetHappiness(true, true);
            AddText("But that's just a regular night for a hero!", true);
            AddWaitForSpace();
            AddText("Ike could barely hold his liquor last night.\nThat's what he gets for challenging Shinon\nto a drinking match! Puked all over his\ncape. Ah, ha ha ha!", true);
            AddWaitForSpace();
            AddText("Can't remember too much else about last\nnight, though. Did I bring anybody home\nwith me?", true);
            AddWaitForSpace();
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("...", false);
            AddWaitForSpace();
            AddCharacter("", false);
            AddCharacter("Shinon", true);
            AddText("...", true);
            AddWaitForSpace();
            AddText("Guess not. Too bad.", true);
            AddWaitForSpace();
            AddText("But there was something...\nWhat was it?", true);
            AddWaitForSpace();
            AddText("Oh yeah... Reyson *shuckle shuckle*\nNow I remember that dream... he was\nwith that other subhuman bird.", true);
            AddWaitForSpace();
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("You know...", false);
            AddWaitForSpace();
            AddText("You know... subhumans don't usually\nturn me on, but Reyson's got that\nkind of body you could just ravage.", false);
            AddWaitForSpace();
            AddText("Maybe I'll go take a look around for him.\nWith no relief last night, I would rather\nenjoy taking pleasure of him.", false);
            
            AddWaitForSpace();
            AddChangeState(new StoryState(0, 3));
        }

        void Scene0_3_FirstLoadRhys()
        {
            Background = new Animation(@"Textures\CG\Town");
            AddBackground(Background);
            AddCharacter("Shinon", true);
            AddText("Sigh...", true);
            AddWaitForSpace();
            AddText("Sigh... This is hopeless. Noobody\naround here has seen Reyson in days.", true);
            AddWaitForSpace();
            AddText("Just my luck he'd disappear the moment\nI got a taste for heron boys. I wonder\nwhere he's flown off to?", true);
            AddWaitForSpace();
            AddText("Maybe he's with that hawk boy I dreamt\nwas scratching him up...", true);
            AddWaitForSpace();
            AddText("...", true);
            AddWaitForSpace();
            AddText("... ...", true);
            AddWaitForSpace();
            AddCharacter("Rhys", false);
            AddText("Donations! Donations anybody? The\nMedicine Men organization needs your\nsupport! How about you good sir?\nOh hey, is that you Shinon?", false);
            AddWaitForSpace();
            AddText("Hey Rhys! You're looking slender\nas always.", true);
            AddWaitForSpace();
            AddText("And you look pretty muscular yourself.\n", false);
            AddWaitForSpace();
            AddText("So what are you doing here, Rhys?", true);
            AddWaitForSpace();
            AddText("I'm collecting donations for my\norganization, The Medicine Men. For\ntoo long, healing has primarily been\ndominated by women.", false);
            AddWaitForSpace();
            AddText("I want to train young men in the art of\nhealing so that the too can feel the rush\nof questing as a vulnerable cleric\nsurrounded by ripped brutes.", false);
            AddWaitForSpace();
            AddText("Sounds like quite the noble cause!\nI'll be happy to assist in any training\nexcerises you think the men need.", true);
            AddWaitForSpace();
            AddText("Sigh... Speaking of which, you haven't\nheard from Reyson recently, have you?", true);
            AddWaitForSpace();
            AddText("I heard there was some trouble at Serenes\nForest. Maybe you should go check it out?", false);
            AddWaitForSpace();
            AddText("Good idea, thanks for the tip!", true);
            
            AddWaitForSpace();
            AddChangeState(new StoryState(0, 4));
        }

        void Scene0_4_FirstLoadForest()
        {
            Background = new Animation(@"Textures\CG\Forest");
            AddBackground(Background);
            AddCharacter("Shinon", true);
            AddText("...", true);
            AddWaitForSpace();
            AddText("Maybe I shouldn't have come all by\nmyself. I am totally lost. All these damn\ntrees look the same. And who knows what\nthe hell is out in this forest.", true);
            AddWaitForSpace();
            AddText("Hey what's that sound? Is that... rustling?\nIt sounds like it's coming from that tree\nover there...", true);
            AddWaitForSpace();
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("...", false);
            AddWaitForSpace();
            AddText("Is that...?!", false);
            
            AddWaitForSpace();
            AddChangeState(new StoryState(0, 5));
        }

        void Scene0_5_FirstLoadElves()
        {
            Background = new Animation(@"Textures\CG\SerenesElves");
            AddBackground(Background);
            AddWaitForSpace();
            AddText("Nnng...", false);
            AddWaitForSpace();
            AddText("Nnng... Uhhn...", false);
            AddWaitForSpace();
            AddText("Nnng... Uhhn... Ohhh...", false);
            AddWaitForSpace();
            AddText("Yes... Please... Nnng...", false);
            AddWaitForSpace();
            AddText("Please... Nibble... Softer... Ahhnng...", false);
            AddWaitForSpace();
            AddCharacter("Shinon", true);
            AddSetPortraitVisibility(false);
            AddText("(Wow, those two are really going at it.)", true);
            AddWaitForSpace();
            AddText("(The bigger one has the smaller one shoved\nup against that tree, and he's really\npounding him hard and fast. Almost seems\nlike that much should be hurting him.)", true);
            AddWaitForSpace();
            AddText("Ahh... Yes... Scratch me...", false);
            AddWaitForSpace();
            AddText("So... Big... So... Hard...", false);
            AddWaitForSpace();
            AddText("(I can't stop watching. The big one looks\nlike he's in esctasy, like he's in a continuous\nstate of orgasm. His body is surprisingly\nimmaculate for an elf in the forest.)", true);
            AddWaitForSpace();
            AddText("(The small one is battered, scratched,\ncovered in bodily fluids and crying. Yet,\nhis cock is rock hard against the tree, and I\ncan see the pleasure behind his teary eyes.)", true);
            AddWaitForSpace();
            AddText("My...ng... leg! ... Ah... ahhh...!", false);
            AddWaitForSpace();
            AddText("(As I watch, the big one roughly thrusts\nthe smaller's leg up against the tree, giving\nme a clear view of the long, thick cock\ntirelessly ramming the other's tight hole.)", true);
            AddWaitForSpace();
            AddText("Ahh... so... fast...!", false);
            AddWaitForSpace();
            AddCharacter("Pleasure", false);
            AddText("Are you enjoying the show I've laid out\nfor you? My name is Pleasure, and it's\nmy pleasure to meet you.", false);
            AddWaitForSpace();
            AddText("Well? Don't be rude to our guest, introduce\nyourself.", false);
            AddWaitForSpace();
            AddCharacter("Pain", false);
            AddText("My... name... is... nng-Aaah!... Pain...", false);
            AddWaitForSpace();
            AddText("I'm... I'm Shinon. You sure you don't want\nto take a break for a minute to chat?\nI'm totally lost (and the small one looks\nlike he's about to burst out crying...)", true);
            AddWaitForSpace();
            AddCharacter("Pleasure", false);
            AddText("Such a human. Elves have no need to slow.\nWe are masters of efficiency, so I shall\ncombine our banal chat with pleasures\nbeyond mankind's understanding.", false);
            AddWaitForSpace();
            AddText("(As Pleasure spoke, I saw him wrap his left\narm around Pain's neck with his hand\nharshly grabbing at Pain's nipple. His right\narm circled Pain's leg and grasped his cock.)", true);
            AddWaitForSpace();
            AddText("So, Shinon, what brings you to Serenes, the\nforest of Elves?", false);
            AddWaitForSpace();
            AddCharacter("Pain", false);
            AddText("Aaaah! Ohhhhh!!", false);
            AddWaitForSpace();
            AddText("(Pain shouted as his body was rocked\nby an intense orgasm as his cock spewed\njets of cum all over, covering the tree,\nhis own body and Pleasure's hand.)", true);
            AddWaitForSpace();
            AddText("(I was in shock. Pleasure raised his\nhand and Pain obediently leaned forward\nto lick his master's hand clean.)", true);
            AddWaitForSpace();
            AddCharacter("Pleasure", false);
            AddText("Well?", false);
            AddWaitForSpace();
            AddText("I... I'm here looking for a heron\nprince named Reyson. He has disappeared\nand I was hoping he had just come home.", true);
            AddWaitForSpace();
            AddText("Ah yes, I did see Prince Reyson\nrecently. He was with that lout, Tibarn.\nTibarn... that fiend has seduced the Prince.", false);
            AddWaitForSpace();
            AddText("I think Tibarn aims to burn down\nSerenes Forest to rid himself of a hawk's\nonly natural enemy: the Elven Archer.", false);
            AddWaitForSpace();
            AddText("He has Reyson locked up just outside the\nforest, where Elves cannot tread. You must\ntake this artifact and save the forest!", false);
            
            AddWaitForSpace();
            AddChangeState(new TitleScreenState());
        }

        void Scene1_1()
        {
            Background = new Animation(@"Textures\CG\OutsideShack");
            AddBackground(Background);
            AddCharacter("Shinon", true);
            AddText("Reyson! Where are you?", true);
            AddWaitForSpace();
            AddText("Shinon, calm yourself. I am in here.", false);
            AddWaitForSpace();
            AddText("Phew, I was worried. Let me get inside and\nI'll make sure you're unharmed.", true);
            AddWaitForSpace();
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("...", false);
            AddWaitForSpace();
            AddText("Reyson, the door is locked!", false);
            AddWaitForSpace();
            AddCharacter("Shinon", true);
            AddCharacter("", false);
            AddText("Reyson, the door is locked!", true);
            AddWaitForSpace();
            AddText("Of course it is, silly. Tibarn locked it to protect me.\nHe's always looking out for me.", false);
            AddWaitForSpace();
            AddText("Reyson, I think Tibarn's cast a spell of\nenchantment on you.", true);
            AddWaitForSpace();
            AddText("But we have bigger issues right now... a\nbattalion of infintry just appeared over the\nhorizon. They must be after you, Reyson!\nDon't worry, I'll save you from them!", true);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 1));
        }
        
        void Scene1_2()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Shinon", false);
            AddText("Prince Reyson! Are you unharmed?", false);
            AddWaitForSpace();
            AddBackground(Inside);
            AddCharacter("Reyson", true);
            AddCharacter("", false);
            AddText("But of course, Shinon. Weren't you\nlistening? The door is locked, so I'm safe!", true);
            AddWaitForSpace();
            AddText("You're only safe because I have been protecting\nyou, not Tibarn. I have already slain dozens of men\nwho would do you harm. All Tibarn does is prevent you\nfrom leaving this prison!", false);
            AddWaitForSpace();
            AddText("That is foolishness! Tibarn is the\nonly one who cares about me!", true);
            AddWaitForSpace();
            AddBackground(Outside);
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("Blast, there's no time to argue... Here they\ncome again! And worse yet, it appears they\nbrought some summoners. I am Prince\nReyson's only defense!", false);

            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 2));
        }

        void Scene1_3()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Animation FireArrow = new Animation(@"Textures\CG\FireArrow");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Shinon", false);
            AddText("Wow, those summoners are tough. If I don't\nkeep an eye out for them, they will\noverwhelm me.", false);
            AddWaitForSpace();
            AddText("Speaking of overwhelmed, I have no\nidea what to do about Reyson.", false);
            AddWaitForSpace();
            AddText("Hrm... Oh, that would probably help,\nbut it's probably dangerous.", false);
            AddWaitForSpace();
            AddText("Gotta do something... Here goes nothing...\nLet's light up the sky!", false);
            AddWaitForSpace();
            AddBackground(FireArrow);
            AddText(null, false);
            AddSetPortraitVisibility(false);
            AddWaitForSpace();
            AddText("Well, the good news is that should get\nRhys's attention. The bad news is that I got\nall the soldiers' attentions too...", false);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 3));
        }

        void Scene1_4()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Rhys", false);
            AddText("Shinon, are you around here? I thought\na saw your fire arrow flare.", false);
            AddWaitForSpace();
            AddCharacter("Shinon", true);
            AddText("Rhys thank Heaven you're here!", true);
            AddWaitForSpace();
            AddText("Woah, Shinon, you look a little rough.", false);
            AddWaitForSpace();
            AddText("It's nothing for a hero like me.", true);
            AddWaitForSpace();
            AddText("Well, at least let me heal you.", false);
            AddWaitForSpace();
            AddText("...", false);
            AddWaitForSpace();
            AddText("Thanks, Rhys. I feel a lot better.", true);
            AddWaitForSpace();
            AddText("Blast! It looks like I was followed\nhere by that group of officers. They look\npretty dangerous, Shinon!", false);
            AddWaitForSpace();
            AddText("Officers? No problem! I'll explain\nthe flare later, for now, I gotta go save\nthe day!", true);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 4));
        }

        void Scene1_5()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Rhys", true);
            AddCharacter("Shinon", false);
            AddText("Whew. That was close. So what's\ngoing on here Shinon?", true);
            AddWaitForSpace();
            AddText("It's Reyson, he's in trouble!", false);
            AddWaitForSpace();
            AddText("Oh, you found him?", true);
            AddWaitForSpace();
            AddText("Yeah, with the help of some Elves, who\ngave me this bow for saving Reyson.", false);
            AddWaitForSpace();
            AddText("How does that help?", true);
            AddWaitForSpace();
            AddText("The one behind the kidnapping is Tibarn,\nking of the hawks. And as every archer\nknows, hawks are weak to arrows, and\nthat goes double for Elven arrows.", false);
            AddWaitForSpace();
            AddText("And Reyson is locked in that house?", true);
            AddWaitForSpace();
            AddText("Yeah, and I can't seem to get it unlocked.", false);
            AddWaitForSpace();
            AddText("I have an idea, but first it looks like\nwe're going to have to take care of some\nmore officers!", true);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 5));
        }

        void Scene1_6()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Rhys", true);
            AddCharacter("Shinon", false);
            AddText("So I think Reyson has had his willpower\nstolen from him.", true);
            AddWaitForSpace();
            AddText("He believes whatever Tibarn wants him to\nbelieve because he literally can't say 'no.'", true);
            AddWaitForSpace();
            AddText("So we have to teach Reyson how to\nbelieve in himself again or some crap?", false);
            AddWaitForSpace();
            AddText("No, he's physically had his willpower stolen.\nWe need to find it and then merge it\nwith him again.", true);
            AddWaitForSpace();
            AddText("So what, somebody out there is holding\nReyson's crystalized willpower? How\nare we going to be able to find them?", false);
            AddWaitForSpace();
            AddText("Pretty much, yeah. Maybe one of these\nthieves is holding it!", true);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 6));
        }

        void Scene1_7()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Rhys", false);
            AddCharacter("Shinon", true);
            AddText("No... those were all petty thieves.", true);
            AddWaitForSpace();
            AddText("So what? You think the master thief is\njust going to come attack us? That doesn't\nmake sense. We need some way to lure\nthem out.", true);
            AddWaitForSpace();
            AddText("You could strip me and use me as bait.", false);
            AddWaitForSpace();
            AddText("I like your thinking, but we'll save that\nplan for later. I'm going to try the opposite.", true);
            AddWaitForSpace();
            AddCharacter("", true);
            AddCharacter("Shinon", false);
            AddText("...", false);
            AddWaitForSpace();
            AddSetHappiness(false, false);
            AddText("HEY YOU ASSHOLES!", false);
            AddWaitForSpace();
            AddText("ONE OF YOU HAS SOMETHING I WANT!", false);
            AddWaitForSpace();
            AddText("YOU KNOW WHO YOU ARE!", false);
            AddWaitForSpace();
            AddText("YOU HAVE 10 MINUTES TO COME!", false);
            AddWaitForSpace();
            AddText("AFTER THAT I SHOOT HIM AND\nHE'S GOOD TO NEITHER OF US!", false);
            AddWaitForSpace();
            AddCharacter("Rhys", false);
            AddSetHappiness(true, false);
            AddCharacter("Shinon", true);
            AddSetHappiness(false, true);
            AddText("Well, looks like we riled some\nstronger thieves. Maybe it's one of them!", false);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 7));
        }

        void Scene1_8()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");
            Background = Outside;
            AddBackground(Outside);
            AddCharacter("Rhys", false);
            AddCharacter("Shinon", true);
            AddText("Blast! I killed a bunch, but none of\nthem had Reyson's willpower!", true);
            AddWaitForSpace();
            AddText("Alack the day! What are we to do now?", false);
            AddWaitForSpace();
            AddCharacter("", false);
            AddText("You could fall right into my trap!", false);
            AddWaitForSpace();
            AddText("Who...?!", true);
            AddWaitForSpace();
            AddText("All this time, you thought the soldiers\nwere here to kill Reyson and that you were\nprotecting him.", false);
            AddWaitForSpace();
            AddText("But really, the whole time it was my army,\nand the target was you!", false);
            AddWaitForSpace();
            AddCharacter("Tibarn", false);
            AddText("You!", true);
            AddWaitForSpace();
            AddText("Yes. Me.  I can't have you interrupting\nmy experiments any longer, Shinon.", false);
            AddWaitForSpace();
            AddText("Experiments? What business are you up to?", true);
            AddWaitForSpace();
            AddText("You think I'm going to tell you right\nbefore I kill you? What a waste of time!", false);
            AddWaitForSpace();
            AddCharacter("Rhys", true);
            AddCharacter("Shinon", false);
            AddText("Shinon, prepare yourself!", true);
            
            AddWaitForSpace();
            AddChangeState(new GameState.GameState(1, 8));
        }

        void Scene1_9()
        {
            Animation Outside = new Animation(@"Textures\CG\OutsideShack");
            Animation Inside = new Animation(@"Textures\CG\InsideShack");

            Background = Inside;
            AddBackground(Inside);
            AddCharacter("Shinon", true);
            AddCharacter("Tibarn", false);
            AddSetHappiness(false, false);
            AddText("Shinon...", false);
            AddWaitForSpace();
            AddText("Shinon... Thank you.", false);
            AddWaitForSpace();
            AddSetHappiness(true, false);
            AddText("Here is Reyson's willpower.", false);
            AddWaitForSpace();
            AddCharacter("Rhys", false);
            AddText("Let's see...", false);
            AddWaitForSpace();
            AddText("COMISCEMUS!", false);
            AddWaitForSpace();
            AddCharacter("", false);
            AddText("So what in Tellius is going on?", true);
            AddWaitForSpace();            
            AddText("I think can answer that question.", false);
            AddWaitForSpace();
            AddCharacter("Reyson", false);
            AddText("But first things first, Shinon, you have\nmy eternal gratitude.", false);
            AddWaitForSpace();
            AddText("Your strength and courage has saved\nTibarn and I.", false);
            AddWaitForSpace();
            AddText("This wasn't a plot of Tibarn's making.\nAt least, not directly...", false);
            AddWaitForSpace();
            AddText("You see, like me, Tibarn hasn't had\nhis willpower. But unlike me, his willpower\nwas been dampened by a spell, instead of\ncrystalized.", false);
            AddWaitForSpace();
            AddCharacter("Tibarn", false);
            AddText("My orders were to discover a way of\ncrystalizing willpower. I fear I succeeded.", false);
            AddWaitForSpace();
            AddText("By weakening me greatly, you were\nable to sever the spell's connection, releasing\nme from the other's control.", false);
            AddWaitForSpace();
            AddText("So do either of you have any idea who\nthis is that's controlling you from afar?", true);
            AddWaitForSpace();
            AddText("...", false);
            AddWaitForSpace();
            AddCharacter("Reyson", false);
            AddText("...", false);
            AddWaitForSpace();
            AddCharacter("", false);
            AddText("So you're saying that somebody out there\ncan remotely control whomever they want,\nand we can't even tell?", true);
            AddWaitForSpace();
            AddText("Damn it... sigh... well I guess the only\nthing left to do for now is get drunk.\nWho's with me?", true);
            AddWaitForSpace();
            AddCharacter("Reyson", false);
            AddText("I'll join you... my hero.", false);
            AddWaitForSpace();
            AddEndQuest();
        }
    }
}
